package com.weibo.action;

import com.opensymphony.xwork2.ActionSupport;
import com.weibo.common.SessionManager;
import com.weibo.pojo.Tuser;
import com.weibo.pojo.Tweibo;
import com.weibo.service.IWeiboService;

/**
 * user for weibo operation
 * 
 * @author vorce
 * 
 */
public class WeiboAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4944156739129982603L;

	private IWeiboService weiboService;
	private Integer weiboId;
	private Tweibo weibo;

	/**
	 * delete one weibo
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception {
		Tuser user = (Tuser) SessionManager.getAttribute("nowUser");
		weibo = weiboService.getWeiboById(weiboId);
		if (user != null && user.getUserId() == weibo.getWeiboOwner()) {
			System.out.println("weiboOwner is " + weibo.getWeiboOwner());
			weiboService.deleteWeibo(weibo);
			
			System.out
					.println(weibo.getWeiboId() + "delete has been deleted. ");
		}
		return "home";
	}

	/**
	 * transpond one weibo
	 * 
	 * @return
	 * @throws Exception
	 */
	public String republic() throws Exception {
		return "home";
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String favourite() throws Exception {
		return "home";
	}

	/**
	 * comment one weibo
	 * 
	 * @return
	 * @throws Exception
	 */
	public String comment() throws Exception {
		return "home";
	}

	public IWeiboService getWeiboService() {
		return weiboService;
	}

	public void setWeiboService(IWeiboService weiboService) {
		this.weiboService = weiboService;
	}

	public Integer getWeiboId() {
		return weiboId;
	}

	public void setWeiboId(Integer weiboId) {
		this.weiboId = weiboId;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

}
